package com.example.bob.usingbc;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    private Button btnbc, btnRegBCR, btnUnRegBCR;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnbc = (Button) findViewById(R.id.btnbc);
        btnRegBCR = (Button) findViewById(R.id.btnRegBCR);
        btnUnRegBCR = (Button) findViewById(R.id.btnUnRegBCR);

        btnbc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent i = new Intent(MainActivity.this, MyBC.class);
                Intent i = new Intent(MyBC.ACTION);
                i.putExtra("txt", "message");
                sendBroadcast(i);
            }
        });
        btnRegBCR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                registerReceiver(mybc, new IntentFilter(MyBC.ACTION));
            }
        });
        btnUnRegBCR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                unregisterReceiver(mybc);
            }
        });
    }

    private final MyBC mybc = new MyBC();

}
